***********************************************************************************
* RIPE paper "A local political economy of IMF programs"
*
* 19 August 2022
* Contact: bernhard.reinsberg@glasgow.ac.uk
***********************************************************************************
  
  
* Data and variables
********************

  use "GHFAFR_RIPE", clear 

  tab sapknw
  g knwsap=(sapknw==2)
  lab var knwsap "Heard of IMF SAP"
  
  tab sapmin
  g sap_bad=(sapmin==3|sapmin==4)
  replace sap_bad=. if sapmin>5
  lab var sap_bad "SAP worse for people"
  
  tab sapsat
  g sap_worse=(sapsat==1|sapsat==2)
  lab var sap_worse "SAP worse for me"
  replace sap_w=. if sapsat>5
  
  g x_nofood=povfoo>1 
  replace x_nofood=. if povfoo>=5
  g x_nowat=povwat>1 
  replace x_nowat=. if povwat>=5
  g x_nohth=povhth>1 
  replace x_nohth=. if povhth>=5
  g x_noinc=povinc>1 
  replace x_noinc=. if povinc>=5
  
  g PID=(1)*(pidwin==2)+(2)*(pidwin==1)+(3)*(pidwin==3)
  replace PID=. if pidwin>3
  lab var PID "3=win, 1=neutral, 2=lose"

  g PIDN=3-PID
  replace PIDN=. if PID==1
  lab var PIDN "Opposition supporter"
  
  g psj=occup==10|occup==11|occup==17|occup==20|occup==48
  su psj
  lab var psj "Public-sector worker"
  
  g x_pf=(pfgpre==1|pfgpre==2)
  lab var x_pf "President performance: Dissatisfied"
  g x_sateco=(pfenow==4|pfenow==5)
  lab var x_sateco "Satisfied with economy now"
  g x_pf_past=(pfepas==1|pfepas==2)
  lab var x_pf_past "Economic conditions: Worse than one year ago"
  g x_pf_fut=(pfefut==1|pfefut==2)
  lab var x_pf_fut "Future economy: Expect to be worse"
  g x_supdem=(supdem==1)  
  lab var x_supdem "Democracy supporter"
  g x_satdem=(dmpsat==4|dmpsat==5)
  lab var x_satdem "Satisfied with democracy"
  g x_smarket=(spamar==1|spamar==2)
  lab var x_smarket "Preference for free market"
  g x_scapital=(marear==1|marear==2)
  lab var x_scap "Support for capitalism"
  g x_spubsec=(sparet==1|sparet==2)
  lab var x_spubsec "Support for public sector"
  g x_spri=(spaprv==1|spaprv==2)
  lab var x_spri "Support for privatization"
  
  g x_unemp=(occup==1)
  replace x_unemp=. if occup>50
  replace x_unemp=1 if unemp==2
  lab var x_unemp "Unemployed"
  g x_male=gender==1
  lab var x_male "Male"
  replace age=. if age>100 | age==0
  g lnage=ln(age)
  lab var lnage "Logged age"
  g x_educ=educ>=3 & educ<=4
  lab var x_educ "Educated"
  g x_urb=urbrur==1
  lab var x_urb "Urban"
  g x_radio=medrad==5|medrad==6
  lab var x_rad "Radio listener"
  
  g x_intpol=scint==1
  lab var x_intpol "Politically interested"
  g x_knowfm=sckfin==2
  lab var x_knowfm "Politically knowledageable"
    
  
  encode iso3, g(ccode)
  svyset ccode [pweight=afcombwt] 
  global X  x_male lnage x_urb x_unemp x_educ x_radio x_intpol x_knowfm
  global P  x_satdem x_smarket x_scap x_spub x_spri 
  global E  x_pf_past x_pf_fut x_pf
  global C  growth_WDI infl_cpi_WDI fh_inv icrg_qog
  
  
* Main analysis 
***************

* Illustrative evidence 

  ** Figure 1 
  graph bar sap_w if knwsap==1 & IMF==1, by(psj, note(" ")) over(PIDN, relabel(1 "Government supporter" 2 "Opposition supporter") label) scheme(s1mono) ytitle(SAP made my life worse)
  

* Table 1: IMF program, partisan allegiance, and pocketbook evaluation of the IMF SAP.  

  qui areg sap_w i.PIDN [aw=afcombwt] if knwsap==1 & IMF==0, a(country) vce(cl country)
  est store a11
  qui areg sap_w i.PIDN $X $P [aw=afcombwt] if knwsap==1 & IMF==0, a(country) vce(cl country)
  est store a12
  qui areg sap_w i.PIDN $X $P $E [aw=afcombwt] if knwsap==1 & IMF==0, a(country) vce(cl country)
  est store a13
  qui areg sap_w i.PIDN [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store a14
  qui areg sap_w i.PIDN $X $P [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store a15
  qui areg sap_w i.PIDN $X $P $E [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store a16

  ** Table 1 
  estout a1* using "Table 1.rtf", replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.* ) stats(N r2_a, fmt(0 3))   

  est restore a13
  margins i.PIDN, dydx() 
  est restore a16
  margins i.PIDN, dydx() 
  
  
* Table 2: Partisan allegiance, occupational group, and pocketbook evaluation of the IMF SAP.

  qui areg sap_w i.PIDN##psj [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store a21
  qui areg sap_w i.PIDN##psj $X $P [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store a22
  qui areg sap_w i.PIDN##psj $X $P $E [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store a23

  ** Table 2 
  estout a2*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.* ) stats(N r2_a, fmt(0 3))   

  est restore a23
  margins psj#PIDN, dydx() 
  est restore a21
  margins psj#PIDN, dydx() 


* Table 3: IMF conditionality, partisan allegiance, and pocketbook evaluation of the IMF SAP. 

  su QCB if IMF==1, d 
  qui areg sap_w i.PIDN [aw=afcombwt] if knwsap==1 & QCB>=24 & IMF==1, a(country) vce(cl country)
  est store a31
  qui areg sap_w i.PIDN $X $P [aw=afcombwt] if knwsap==1 & QCB>=24 & IMF==1, a(country) vce(cl country)
  est store a32
  qui areg sap_w i.PIDN $X $P $E [aw=afcombwt] if knwsap==1 & QCB>=24 & IMF==1, a(country) vce(cl country)
  est store a33
  qui areg sap_w i.PIDN [aw=afcombwt] if knwsap==1 & QCB<24 & IMF==1, a(country) vce(cl country)
  est store a34
  qui areg sap_w i.PIDN $X $P [aw=afcombwt] if knwsap==1 & QCB<24 & IMF==1, a(country) vce(cl country)
  est store a35
  qui areg sap_w i.PIDN $X $P $E [aw=afcombwt] if knwsap==1 & QCB<24 & IMF==1, a(country) vce(cl country)
  est store a36  
  
  ** Table 3 
  estout a3* using "Table 3.rtf", replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.* ) stats(N r2_a, fmt(0 3))   

  est restore a33
  margins PIDN, dydx() 
  est restore a36
  margins PIDN, dydx() 
  
  
* Table 4: Deprivation   

  g depindex=(povfoo<5)*povfoo+ (povwat<5)*povwat +(povhth<5)*povhth +(povinc<5)*povinc -4
  su depindex
  replace depindex=. if depindex<0
  replace depindex=. if iso3=="NGA"|iso3=="UGA"

  qui areg depindex i.PIDN [aw=afcombwt] if IMF==0, a(country) vce(cl country)
  est store a41
  qui areg depindex i.PIDN $X $P [aw=afcombwt] if IMF==0, a(country) vce(cl country)
  est store a42
  qui areg depindex i.PIDN $X $P $E [aw=afcombwt] if IMF==0, a(country) vce(cl country)
  est store a43
  qui areg depindex i.PIDN [aw=afcombwt] if IMF==1, a(country) vce(cl country)
  est store a44
  qui areg depindex i.PIDN $X $P [aw=afcombwt] if IMF==1, a(country) vce(cl country)
  est store a45
  qui areg depindex i.PIDN $X $P $E [aw=afcombwt] if IMF==1, a(country) vce(cl country)
  est store a46
  
  ** Table 4 
  estout a4* using "Table 4.rtf", replace title("") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.*) stats(N r2_a, fmt(0 3))   
  
  
* Appendix
**********  
  
* Table A2  

  su SPCsTOT if IMF==1, d
  qui areg sap_w i.PIDN [aw=afcombwt] if knwsap==1 & SPCs<4 & IMF==1, a(country) vce(cl country)
  est store r11
  qui areg sap_w i.PIDN $X $P [aw=afcombwt] if knwsap==1 & SPCs<4 & IMF==1, a(country) vce(cl country)
  est store r12
  qui areg sap_w i.PIDN $X $P $E [aw=afcombwt] if knwsap==1 & SPCs<4 & IMF==1, a(country) vce(cl country)
  est store r13
  qui areg sap_w i.PIDN [aw=afcombwt] if knwsap==1 & SPCs>=4 & IMF==1, a(country) vce(cl country)
  est store r14
  qui areg sap_w i.PIDN $X $P [aw=afcombwt] if knwsap==1 & SPCs>=4 & IMF==1, a(country) vce(cl country)
  est store r15
  qui areg sap_w i.PIDN $X $P $E [aw=afcombwt] if knwsap==1 & SPCs>=4 & IMF==1, a(country) vce(cl country)
  est store r16
  
  ** Table A2 
  estout r1* using "Table A2.rtf", replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.* ) stats(N r2_a, fmt(0 3))   
 
  est restore r13
  margins PIDN, dydx()
  est restore r16
  margins PIDN, dydx()
  
  
* Table A3 

  qui areg depindex i.PIDN [aw=afcombwt] if QCB>=24 & IMF==1, a(country) vce(cl country)
  est store r21
  qui areg depindex i.PIDN $X $P [aw=afcombwt] if QCB>=24 & IMF==1, a(country) vce(cl country)
  est store r22
  qui areg depindex i.PIDN $X $P $E [aw=afcombwt] if QCB>=24 & IMF==1, a(country) vce(cl country)
  est store r23
  qui areg depindex i.PIDN [aw=afcombwt] if QCB<24 & IMF==1, a(country) vce(cl country)
  est store r24
  qui areg depindex i.PIDN $X $P [aw=afcombwt] if QCB<24 & IMF==1, a(country) vce(cl country)
  est store r25
  qui areg depindex i.PIDN $X $P $E [aw=afcombwt] if QCB<24 & IMF==1, a(country) vce(cl country)
  est store r26

  ** Table A3 
  estout r2* using "Table A3.rtf", replace title("") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.*) stats(N r2_a, fmt(0 3))      
  
  
* Geospatial analysis of Afrobarometer
  
  preserve  
   use "GHFAFR_RIPE_GEO", clear 
  
   g maj_opp=1-maj_gov
   g vs_opp=1-vs_gov
   
   qui areg sap_w vs_opp [aw=afcombwt] if sapknw==1 & IMF==1, a(country) vce(cl country)
   est store d11
   qui areg sap_w vs_opp $X $P [aw=afcombwt] if sapknw==1 & IMF==1, a(country) vce(cl country)
   est store d12
   qui areg sap_w vs_opp $X $P $E [aw=afcombwt] if sapknw==1 & IMF==1, a(country) vce(cl country)
   est store d13

   ** Table A4
   estout d1*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons ) stats(N r2_a, fmt(0 3))   
  
   qui areg sap_w vs_opp i.PIDN [aw=afcombwt] if sapknw==1 & IMF==1, a(country) vce(cl country)
   est store d21
   qui areg sap_w vs_opp i.PIDN $X $P [aw=afcombwt] if sapknw==1 & IMF==1, a(country) vce(cl country)
   est store d22
   qui areg sap_w vs_opp i.PIDN $X $P $E [aw=afcombwt] if sapknw==1 & IMF==1, a(country) vce(cl country)
   est store d23

   ** Table A5
   estout d2*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.*) stats(N r2_a, fmt(0 3))   
  restore 
  
  
* Survey-adjusted probit 

  qui probit sap_w i.PIDN [pw=afcombwt] if knwsap==1 & IMF==1, vce(cl country) iterate(50)
  est store r51
  qui probit sap_w i.PIDN $X $P [pw=afcombwt] if knwsap==1 & IMF==1, vce(cl country) iterate(50)
  est store r52
  qui probit sap_w i.PIDN $X $P $E [pw=afcombwt] if knwsap==1 & IMF==1, vce(cl country) iterate(50)
  est store r53

  ** Table A6
  estout r5*, title("") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.*) stats(N r2_p, fmt(0 3))   

  qui probit sap_w i.PIDN##psj [pw=afcombwt] if knwsap==1 & IMF==1, vce(cl country)
  est store r61
  qui probit sap_w i.PIDN##psj $X $P [pw=afcombwt] if knwsap==1 & IMF==1, vce(cl country)
  est store r62
  qui probit sap_w i.PIDN##psj $X $P $E [pw=afcombwt] if knwsap==1 & IMF==1, vce(cl country)
  est store r63
  
  ** Table A7 
  estout r6*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.* ) stats(N r2_p, fmt(0 3))   

    
* MLM probit + country level features 

  mat D=J(2,3,0)
  qui mixed sap_w i.PIDN $C [pw=afcombwt] if knwsap==1 & IMF==1 || country:, vce(cl country) iterate(50)
  est store r71
  mat D[1,1]=e(N)
  qui reg sap_w i.PIDN $C [aw=afcombwt] if knwsap==1 & IMF==1
  mat D[2,1]=e(r2_a)
  qui mixed sap_w i.PIDN $X $P $C [pw=afcombwt] if knwsap==1 & IMF==1 || country:, vce(cl country) iterate(50)
  est store r72
  mat D[1,2]=e(N)
  qui reg sap_w i.PIDN $X $P $C [aw=afcombwt] if knwsap==1 & IMF==1
  mat D[2,2]=e(r2_a)
  qui mixed sap_w i.PIDN $X $P $E $C [pw=afcombwt] if knwsap==1 & IMF==1 || country:, vce(cl country) iterate(50)
  est store r73
  mat D[1,3]=e(N)
  qui reg sap_w i.PIDN $X $P $E $C [aw=afcombwt] if knwsap==1 & IMF==1
  mat D[2,3]=e(r2_a)
  
  ** Table A8
  estout r7*, title("") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.*) stats(N converged, fmt(0 0))   
  mat li D

  qui mixed sap_w i.PIDN##psj $C [pw=afcombwt] if knwsap==1 & IMF==1 || country:, vce(cl country)
  est store r81
  mat D[1,1]=e(N)
  qui reg sap_w i.PIDN##psj $C [aw=afcombwt] if knwsap==1 & IMF==1
  mat D[2,1]=e(r2_a)
  qui mixed sap_w i.PIDN##psj $X $P $C [pw=afcombwt] if knwsap==1 & IMF==1 || country:, vce(cl country)
  est store r82
  mat D[1,2]=e(N)
  qui reg sap_w i.PIDN##psj $X $P $C [aw=afcombwt] if knwsap==1 & IMF==1
  mat D[2,2]=e(r2_a)
  qui mixed sap_w i.PIDN##psj $X $P $E $C [pw=afcombwt] if knwsap==1 & IMF==1 || country:, vce(cl country)
  est store r83
  mat D[1,3]=e(N)
  qui reg sap_w i.PIDN##psj $X $P $E $C [aw=afcombwt] if knwsap==1 & IMF==1
  mat D[2,3]=e(r2_a)
  
  ** Table A9
  estout r8*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.* ) stats(N converged, fmt(0 3))   
  mat li D
   
  
* Trichotomous indicator of partisan allegiance

  mat G=J(4,3,0)
  qui areg sap_w i.PID [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store t11
   mat G[1,1]=_b[2.PID]-_b[3.PID]
   qui test (2.PID=3.PID)
   mat G[2,1]=`r(p)'/2
   mat G[3,1]=e(N)
   qui reg sap_w i.PID i.country [aw=afcombwt]
   mat G[4,1]=e(r2_a)
  qui areg sap_w i.PID $X $P [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store t12
   mat G[1,2]=_b[2.PID]-_b[3.PID]
   qui test (2.PID=3.PID)
   mat G[2,2]=`r(p)'/2
   mat G[3,2]=e(N)
   qui reg sap_w i.PID $X $P i.country [aw=afcombwt]
   mat G[4,2]=e(r2_a)
  qui areg sap_w i.PID $X $P $E [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store t13
   mat G[1,3]=_b[2.PID]-_b[3.PID]
   qui test (2.PID=3.PID)
   mat G[2,3]=`r(p)'/2
   mat G[3,3]=e(N)
   qui reg sap_w i.PID $X $P $E i.country [aw=afcombwt]
   mat G[4,3]=e(r2_a)
   
  ** Table A10 
  estout t1*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *1.* ) stats(N r2_a, fmt(0 3))   
  mat li G

  
  est restore t13
  margins i.PID, dydx() 
  est restore t11
  margins i.PID, dydx() 

  mat G=J(6,3,0)
  qui areg sap_w i.PID##psj [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store t21
   mat G[1,1]=_b[2.PID#1.psj]-_b[3.PID#1.psj]
   mat G[3,1]=_b[2.PID]-_b[3.PID]
   qui test (2.PID#1.psj=3.PID#1.psj)
   mat G[2,1]=`r(p)'/2
   qui test (2.PID=3.PID)
   mat G[4,1]=`r(p)'/2
   mat G[5,1]=e(N)
   qui reg sap_w i.PID##psj i.country [aw=afcombwt] if knwsap==1 & IMF==1
   mat G[6,1]=e(r2_a)

  qui areg sap_w i.PID##psj $X $P [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store t22
   mat G[1,2]=_b[2.PID#1.psj]-_b[3.PID#1.psj]
   mat G[3,2]=_b[2.PID]-_b[3.PID]
   qui test (2.PID#1.psj=3.PID#1.psj)
   mat G[2,2]=`r(p)'/2
   qui test (2.PID=3.PID)
   mat G[4,2]=`r(p)'/2
   mat G[5,2]=e(N)
   qui reg sap_w i.PID##psj $XP $P i.country [aw=afcombwt] if knwsap==1 & IMF==1
   mat G[6,2]=e(r2_a)
   
  qui areg sap_w i.PID##psj $X $P $E [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store t23
   mat G[1,3]=_b[2.PID#1.psj]-_b[3.PID#1.psj]
   mat G[3,3]=_b[2.PID]-_b[3.PID]
   qui test (2.PID#1.psj=3.PID#1.psj)
   mat G[2,3]=`r(p)'/2
   qui test (2.PID=3.PID)
   mat G[4,3]=`r(p)'/2
   mat G[5,3]=e(N)
   qui reg sap_w i.PID##psj $XP $P $E i.country [aw=afcombwt] if knwsap==1 & IMF==1
   mat G[6,3]=e(r2_a) 
   
  ** Table A11  
  estout t2*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons 1.* *0.* ) stats(N r2_a, fmt(0 3))   
  mat li G
  
  est restore t23
  margins psj#PID, dydx() 
  est restore t21
  margins psj#PID, dydx() 


* Institutional features: all-party government

  g ngovp=1*(dpi_gps1>0)+1*(dpi_gps2>0)+1*(dpi_gps3>0)
  g n3=ngovp==3

  qui reg sap_w i.PIDN##n3 [aw=afcombwt] if knwsap==1 & ngovp>0, vce(cl country)
  est store m11
  qui reg sap_w i.PIDN##n3 $X $P [aw=afcombwt] if knwsap==1 & ngovp>0, vce(cl country)
  est store m12
  qui reg sap_w i.PIDN##n3 $X $P $E [aw=afcombwt] if knwsap==1 & ngovp>0, vce(cl country)
  est store m13
  
  ** Table A12 
  estout m1*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.* ) stats(N r2_a, fmt(0 3))   
  margins n3#i.PIDN, dydx() vce(uncond)


* Sociotropic evaluations

  qui areg sap_b i.PIDN [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store b11
  qui areg sap_b i.PIDN $X $P [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store b12
  qui areg sap_b i.PIDN $X $P $E [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store b13
  
  ** Table A13 
  estout b1*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.* ) stats(N r2_a, fmt(0 3))   

  est restore b13
  margins i.PIDN, dydx() 
  est restore b11
  margins i.PIDN, dydx() 

  qui areg sap_b i.PIDN##psj [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store b21
  qui areg sap_b i.PIDN##psj $X $P [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store b22
  qui areg sap_b i.PIDN##psj $X $P $E [aw=afcombwt] if knwsap==1 & IMF==1, a(country) vce(cl country)
  est store b23
  
  ** Table A14
  estout b2*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons *0.* ) stats(N r2_a, fmt(0 3))   

  est restore b23
  margins psj#PIDN, dydx() 
  est restore b21
  margins psj#PIDN, dydx() 

  
* Leave one out validation 

  mat B=J(12,4,0)
  foreach i in  2 4 5 9 10 11 12{
  qui areg sap_w i.PIDN $X $P $E [aw=afcombwt] if knwsap==1 & IMF==1 & country!=`i', a(country) vce(cl country)
   mat b=e(b)
   mat s=e(V)
   mat B[`i',1]=b[1,2]
   mat B[`i',2]=sqrt(s[2,2])
  qui areg sap_w i.PIDN##psj $X $P [aw=afcombwt] if knwsap==1 & IMF==1 & country!=`i', a(country) vce(cl country)
   mat b=e(b)
   mat s=e(V)
   mat B[`i',3]=b[1,8]
   mat B[`i',4]=sqrt(s[8,8])
  }
  
  ** Table A15
  mat li B
  
  
* Replication with ethnic allegiances

  g ethn01=.
  lab var ethn01 "Powerful group"
 
  tab language if country==1
  replace ethn01=0 if country==1
  replace ethn01=. if country==1 & (language==6|language==7)
  replace ethn01=1 if country==1 & (language==15)
  tab language if country==2
  ** nobody is powerless **
  tab language if country==3
  ** irrelevant **
  tab language if country==4
  replace ethn01=0 if country==4
  replace ethn01=1 if country==4 & (language==2 |language==28 |language==31 | language==33)
  replace ethn01=. if country==4 & language==4
  tab language if country==5
  tab language if country==6
  replace ethn01=1 if country==6 & language==10
  tab language if country==7
  replace ethn01=0 if country==7 & (language==99 |language==98 |language==133)
  replace ethn01=1 if country==7 & (language==95 |language==96)
  tab language if country==8
  tab language if country==9
  replace ethn=1 if country==9 & language==196
  replace ethn=0 if country==9 & language==205
  tab language if country==10
  tab language if country==11
  tab language if country==12

  g ethn00=1-ethn01

  qui areg sap_w i.ethn00 [aw=afcombwt] if knwsap==1, a(country) vce(cl country)
  est store e11
  qui areg sap_w i.ethn00 $X $P [aw=afcombwt] if knwsap==1, a(country) vce(cl country)
  est store e12
  qui areg sap_w i.ethn00 $X $P $E [aw=afcombwt] if knwsap==1, a(country) vce(cl country)
  est store e13
  
  ** Table A16
  estout e1*, replace title("LPM-FE") note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_cons 0.* ) stats(N r2_a, fmt(0 3))   
   
  
* Descriptive statistics 

  ** Table A1
  qui estpost su sap_w sap_b depindex x_no* PID* ethn00 psj $X $P $E knwsap SPCs QCB IMF $C if IMF>0 & knwsap==1
  esttab ., cells("count mean sd min max")
  
  
  
* Figures   
  
  ** Figure A1 
  graph bar if knwsap==1 & IMF==1 & sapsat<=5, over(sapsat, label(angle(90))) scheme(s1mono)
  tab sapsat if knwsap==1 & IMF==1 & sapsat<=5
  
  ** Figure A2
  graph bar if knwsap==1 & IMF==1 & sapmin<=5, over(sapmin, label(angle(90))) scheme(s1mono)
  tab sapmin if knwsap==1 & IMF==1 & sapmin<=5
   
  ** Figure A3
  graph bar if knwsap==1 & IMF==1, over(PID) scheme(s1mono) ytitle(Percent) 
  tab PID if knwsap==1 & IMF==1
  
  ** Figure A4: Quantitative conditions, partisan allegiance, and pocketbook evaluation of the IMF SAP
  g BAany=0
  replace BAany=1 if QCB>=24
  graph bar sap_w if knwsap>0 & IMFnn>0, over(PIDN, relabel(1 "Government supporter" 2 "Opposition supporter") label) by(BAany, note(" ")) ytitle(SAP made my life worse) scheme(s1mono) 

  * Figure A5: Structural conditions, partisan allegiance, and pocketbook evaluation of the IMF SAP.
  replace BAany=1 if SPCs>3
  graph bar sap_w if knwsap>0 & IMFnn>0, over(PIDN, relabel(1 "Government supporter" 2 "Opposition supporter") label) by(BAany, note(" ")) ytitle(SAP made my life worse) scheme(s1mono) 
  
    
  * Balance tests 
  preserve
   collapse IMFnn growth crisis eco_glob KOFPoGI fh_inv physint leftany gdppc sfi_SFI civwar icrg_qog v2x_corr Xdebt reserves infl_cpi trade s_unga [aw=afcombwt], by(country iso3)
   mat M=J(17,4,0)
   local m=1
   foreach x in growth crisis eco_glob KOFPoGI fh_inv physint leftany gdppc sfi_SFI civwar icrg_qog v2x_corr Xdebt reserves infl_cpi trade s_unga {
   qui ttest `x', by(IMFnn) une
   mat M[`m',1]=r(mu_1)
   mat M[`m',2]=r(mu_2)
   mat M[`m',3]=r(mu_2)-r(mu_1)
   mat M[`m',4]=r(p)
   local m=`m'+1
   }
  restore 
  
  ** Table B2 
  mat li M 
   